package cn.eeepay.boss.action.workOrder;


import cn.eeepay.boss.system.DataSource;
import cn.eeepay.boss.system.SystemLog;
import cn.eeepay.framework.db.pagination.Page;
import cn.eeepay.framework.model.workOrder.WorkWarningInfo;
import cn.eeepay.framework.service.workOrder.WorkWarningService;
import cn.eeepay.framework.util.Constants;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 工单预警
 */
@RequestMapping("/workWarning")
@Controller
public class WorkWarningAction {

    private Logger log = LoggerFactory.getLogger(WorkWarningAction.class);

    @Resource
    private WorkWarningService workWarningService;

    /**
     * 工单预警查询
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/selectWorkWarningList")
    @ResponseBody
    public Map<String,Object> selectWorkWarningList(@RequestParam("info") String param, @ModelAttribute("page") Page<WorkWarningInfo> page){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            WorkWarningInfo info = JSONObject.parseObject(param, WorkWarningInfo.class);
            workWarningService.selectWorkWarningList(info, page);
            msg.put("page",page);
            msg.put("status", true);
        } catch (Exception e){
            log.error("工单预警查询异常!",e);
            msg.put("status", false);
            msg.put("msg", "工单预警查询异常!");
        }
        return msg;
    }

    /**
     * 关闭工单预警记录
     */
    @RequestMapping(value = "/closeWorkWarning")
    @SystemLog(description = "关闭工单预警记录")
    @ResponseBody
    public Map<String,Object> closeWorkWarning(@RequestParam("id") Long id){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            workWarningService.closeWorkWarning(id, msg);
        } catch (Exception e){
            log.error("关闭工单预警记录异常!",e);
            msg.put("status", false);
            msg.put("msg", "关闭工单预警记录异常!");
        }
        return msg;
    }
}
